home *** CD-ROM | disk | FTP | other *** search
/ Aminet 21 / Aminet 21 (1997)(GTI - Schatztruhe)[!][Oct 1997].iso / Aminet / comm / bbs / cit_src_7H21.lha / logstat.c < prev    next >
C/C++ Source or Header  |  1997-07-27  |  4KB  |  176 lines

  1. #define TITLE   "Citadel User Log statistics "
  2.  
  3. #include "ctdl.h"    /* header file  */
  4. #include <stdio.h>
  5. #include <string.h>
  6. #include <stdlib.h>
  7. #include <math.h>
  8. #include <ctype.h>
  9. #include <time.h>
  10. #include <proto/exec.h>
  11. #include <dos/dos.h>
  12. #include <pragmas/dos_pragmas.h>
  13. #include "exec/memory.h"
  14. #include "exec/ports.h"
  15. #include "exec/exec.h"
  16.  
  17. extern CONFIG    cfg;            /* A buncha variables           */
  18. extern logBuffer logBuf;         /* Pippul buffer                */
  19. extern FILE             *logfl;         /* log file descriptor          */
  20. extern LogTable    *logTab;
  21. SListBase MailForward = { NULL, CheckFwd, NULL, NULL, EatForwarding };
  22.  
  23. char dodebug = FALSE;
  24.  
  25. void Analyze(void);
  26. void Display(void);
  27. FILE *fopen();
  28.  
  29. int Floors = 0,
  30.     Lfmask = 0,
  31.     Expert = 0,
  32.     Aide = 0,
  33.     Time = 0,
  34.     Oldtoo = 0,
  35.     Net = 0,
  36.     entry,
  37.     hi = 0,
  38.     low = 0,
  39.     Forward = 0,
  40.     Nulls = 0,
  41.     ECD = 0,
  42.     Halfdup = 0;
  43.  
  44. /*
  45.  * main()
  46.  *
  47.  * Main manager.
  48.  */
  49. int main(int ,char **);
  50. int main(argc,argv)
  51. int  argc;
  52. char **argv;
  53. {
  54.     int i;
  55.     SYS_FILE fn;
  56.     extern char *READ_ANY;
  57.  
  58.     cfg.weAre = UTILITY;
  59.     printf("%s %s\n%s\n",TITLE, VERSION_NAME, COPYRIGHT);
  60.     if (!readSysTab(FALSE, TRUE)) exit(1);
  61.     makeSysName(fn, "ctdllog.sys", &cfg.logArea);
  62.     if ((logfl = fopen(fn, READ_ANY)) == NULL) {
  63.         printf("Can't open the Citadel log!\n");
  64.         exit(1);
  65.     }
  66.     initLogBuf(&logBuf);
  67.     makeSysName(fn, "ctdlfwd.sys", &cfg.roomArea);
  68.     MakeList(&MailForward, fn, NULL);
  69.  
  70.     entry = 0;
  71.     for ( i = 0; i < cfg.MAXLOGTAB; i++ ) {
  72.         getLog(&logBuf,i);
  73.         fprintf(stderr, "log #%-4d\r",i);
  74.         if (logBuf.lbflags.L_INUSE) {
  75.             entry++;
  76.             Analyze();
  77.         }
  78.     }
  79.     Display();
  80.   return 0;
  81. }
  82.  
  83. /*
  84.  * Analyze()
  85.  *
  86.  * This analyzes an account.
  87.  */
  88. void Analyze()
  89. {
  90.     if (logBuf.lbflags.FLOORS) Floors++;
  91.     if (logBuf.lbflags.LFMASK) Lfmask++;
  92.     if (logBuf.lbflags.EXPERT) Expert++;
  93.     if (logBuf.lbflags.AIDE) Aide++;
  94.     if (logBuf.lbflags.TIME) Time++;
  95.     if (logBuf.lbflags.OLDTOO) Oldtoo++;
  96.     if (logBuf.lbflags.NET_PRIVS) Net++;
  97.     if (logBuf.lbflags.HALF_DUP) Halfdup++;
  98.     if (logBuf.lbnulls != 0) Nulls++;
  99.     if (logBuf.lbdelay != 0) ECD++;
  100.     if (SearchList(&MailForward, logBuf.lbname) != NULL)
  101.         Forward++;
  102.     if (logBuf.lbwidth > 41) hi++;
  103.  
  104.     else low++;
  105. }
  106.  
  107. /*
  108.  * Display()
  109.  *
  110.  * Final statistics display.
  111.  */
  112. void Display()
  113. {
  114.     printf("%d accounts in use\n\n", entry);
  115.     printf("%d are using Floor Mode\n", Floors);
  116.     printf("%d have Net privs\n", Net);
  117.     printf("%d use Mail Forwarding\n", Forward);
  118.     printf("%d are Experts\n", Expert);
  119.     printf("%d are Aides\n", Aide);
  120.     printf("%d use Half-duplex mode\n", Halfdup);
  121.     printf("%d use LineFeeds\n", Lfmask);
  122.     printf("%d display the time on messages\n", Time);
  123.     printf("%d display last old on new request\n", Oldtoo);
  124.     printf("%d use more than 0 nulls\n", Nulls);
  125.     printf("%d users have column widths greater than 41, %d less than\n",
  126.                         hi, low);
  127.     printf("%d use .ECD\n", ECD);
  128. }
  129.  
  130. /*
  131.  * crashout()
  132.  *
  133.  * Handles fatal errors.
  134.  */
  135. void crashout(str)
  136. char *str;
  137. {
  138.     exit(printf(str));
  139. }
  140.  
  141. /*
  142.  * CheckFwd()
  143.  *
  144.  * forward mail to whom?
  145.  */
  146. void *CheckFwd(ForwardMail *data, char *who)
  147. {
  148.     return (strCmpU(data->UserName, who) == SAMESTRING) ? data : NULL;
  149. }
  150.  
  151. /*
  152.  * EatForwarding()
  153.  *
  154.  * This will eat a line from ctdlfwd.sys
  155.  * Format: <username><tab><system spec><tab><alias>
  156.  * where "system spec" can be a domain-name.
  157.  * "alias" can be the same as username
  158.  */
  159. void *EatForwarding(char *line)
  160. {
  161.     ForwardMail *data;
  162.     char *tab;
  163.  
  164.     data = GetDynamic(sizeof *data);
  165.     tab = strchr(line, '\t');
  166.     *tab++ = 0;
  167.     data->UserName = strdup(line);
  168.     line = tab;
  169.     tab = strchr(line, '\t');
  170.     *tab++ = 0;
  171.     data->System = strdup(line);
  172.     data->Alias = strdup(tab);
  173.     return data;
  174. }
  175.  
  176.